﻿<%@ Control Language="C#" Inherits="FSC.HaNamAPApplication.HNAP_AdminAPEdit, FSC.HaNamAPApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f1bbb5b0477b356"  compilationMode="Always" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>

<%@ Register src="HNAP_AdminLeftNav.ascx" tagname="HNAP_AdminLeftNav" tagprefix="uc1" %>

<style type="text/css">
    iframe.ms-rtelong, table.ms-rtetoolbarmenu { width:600px; }  
</style>

<link rel="stylesheet" href="~/_layouts/CSS/tabs/themes/base/jquery.ui.all.css" /> <!-- ~/_layouts/CSS/ -->
<script type="text/javascript" src="~/_layouts/CSS/tabs/jquery-1.5.1.js"></script> 
<script type="text/javascript"  src="~/_layouts/CSS/tabs/jquery.ui.core.js"></script> 
<script type="text/javascript"  src="~/_layouts/CSS/tabs/jquery.ui.widget.js"></script> 
<script src="~/_layouts/CSS/tabs/jquery.bgiframe-2.1.2.js"></script>
<script src="~/_layouts/CSS/tabs/jquery.ui.mouse.js"></script>
<script src="~/_layouts/CSS/tabs/jquery.ui.button.js"></script>
<script src="~/_layouts/CSS/tabs/jquery.ui.draggable.js"></script>
<script src="~/_layouts/CSS/tabs/jquery.ui.position.js"></script>
<script src="~/_layouts/CSS/tabs/jquery.ui.resizable.js"></script>
<script src="~/_layouts/CSS/tabs/jquery.ui.dialog.js"></script>
<script src="~/_layouts/CSS/tabs/jquery.effects.core.js"></script>

<script type="text/javascript">
    function gmobj(o) {
        if (document.getElementById) { m = document.getElementById(o); }
        else if (document.all) { m = document.all[o]; }
        else if (document.layers) { m = document[o]; }
        return m;
    }
    function GetFileNameWithoutExtension(name) {
        var shortName = name;
        shortName = shortName.replace(/^.*[\\\/]/, '');
        shortName = shortName.split('.').reverse().slice(1).reverse().join('.');
        return shortName;
    }
    var _TotalItem = 1;
    function UploadChange(obj) {
        //alert(parseInt(obj.name.substring(7))+1);
        //alert(obj.name);
        var fText = "fText" + parseInt(obj.name.substring(7))
        document.getElementById(fText).value = GetFileNameWithoutExtension(obj.value);
        AddNewUploadControl(parseInt(obj.name.substring(7)) + 1);
    }
    function AddNewUploadControl(index) {
        if (index == (_TotalItem - 1)) {
            var tr = gmobj("tblUpload").insertRow(index);
            tr.id = index;
            var td1 = tr.insertCell(0);
            td1.vAlign = "top";
            var td2 = tr.insertCell(1);
            td2.vAlign = "middle";
            td1.innerHTML = '<input type="text" name="fText' + index + '" id="fText' + index + '" style="width:250px" /> <input type="file" name="fUpload' + index + '" id="fUpload' + index + '" style="width: 280px;" size=38 onchange="javascript:UploadChange(this)" />';
            td2.innerHTML = '<img src="~/_layouts/CSS/images/minus.gif" name="fButton' + index + '" id=fButton' + index + ' style="cursor:pointer;" onclick="RemoveRow(this)" />';
            _TotalItem++;
        }
    }
    function RemoveRow(objButton) {
        if (gmobj("tblUpload").rows.length == 1) return;
        if (parseInt(objButton.name.substring(7)) == gmobj("tblUpload").rows.length - 1) return;

        var obj;
        var RowIndex = parseInt(objButton.name.substring(7));
        gmobj("tblUpload").deleteRow(RowIndex);
        for (var i = RowIndex + 1; i < _TotalItem; i++) {
            Fix('fText', parseInt(i));
            Fix('fUpload', parseInt(i));
            Fix('fButton', parseInt(i));
        }
        _TotalItem--;
    }
    function Fix(Id, Index) {
        var obj = document.getElementById(Id + Index);
        if (obj) {
            obj.name = Id + parseInt(parseInt(Index) - 1);
            obj.id = Id + parseInt(parseInt(Index) - 1);
        }
    }

    $(function() {

        $("#dialog-form").dialog({
            autoOpen: false,
            height: 350,
            width: 800,
            modal: true,
            open: function(type, data) {
                $(this).parent().appendTo("form");
            },
            close: function() {
                allFields.val("").removeClass("ui-state-error");
            }
        });


        $("#create-user").click(function() {
            $("#dialog-form").dialog("open");
            return false;
        });
    });

    var _TotalLegal = 0;
    function AddNewLegalControl(docname, docid) {
        var hdfDocs = gmobj("<%=hdfDocsExist.ClientID %>");
        if (hdfDocs.value != "") {
            var docIdArray = hdfDocs.value.split("#");
            for (i = 0; i < docIdArray.length; i++) {
                if (docIdArray[i] == docid) {
                    $("#dialog-form").dialog("close");
                    return;
                }
            }
        }
        
        for (var i = 0; i < _TotalLegal; i++) {
            if (gmobj("dHidden" + i).value == ("doc#" + docid)) {
                $("#dialog-form").dialog("close");
                return;
            }
        }
        var tr = gmobj("tblLegal").insertRow(_TotalLegal);
        tr.id = _TotalLegal;
        var td1 = tr.insertCell(0);
        td1.vAlign = "top";
        var td2 = tr.insertCell(1);
        td2.vAlign = "middle";
        td1.innerHTML = '<a href="<%= CurrentUrlWithoutParam %>?page=DocDetail&did=' + docid + '" target="_blank">' + docname + '</a><input type="hidden" value="doc#' + docid + '" id="dHidden' + _TotalLegal + '" name="dHidden' + _TotalLegal + '" />';
        td2.innerHTML = '<img src="~/_layouts/CSS/images/minus.gif" name="dButton' + _TotalLegal + '" id=dButton' + _TotalLegal + ' style="cursor:pointer;" onclick="RemoveRowLegal(this)" />';
        _TotalLegal++;

        $("#dialog-form").dialog("close");
    }
    function RemoveRowLegal(objButton) {
        if (gmobj("tblLegal").rows.length == 0) return;
        //if (parseInt(objButton.name.substring(7)) == gmobj("tblUpload").rows.length - 1) return;

        var obj;
        var RowIndex = parseInt(objButton.name.substring(7));
        gmobj("tblLegal").deleteRow(RowIndex);
        for (var i = RowIndex + 1; i < _TotalItem; i++) {
            Fix('dHidden', parseInt(i));
            Fix('dButton', parseInt(i));
        }
        _TotalLegal--;
    }

    function SearchDoc() {
        var name = $("#<%= txtDocName.ClientID  %>").val();
        var dropField = $("#<%= ddlDocFields.ClientID %>").val();
        var dropOffice = $("#<%= ddlDocOffices.ClientID %>").val();

        $.ajax({
            type: "POST",
            url: "~/_layouts/HNAP_Services.asmx/GetDocItems",
            // Pass the parameters, via JSON object.
            data: '{"docName":"' + name + '", "docField":"' + dropField + '", "docOffice":"' + dropOffice + '"}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                BuildTable(msg.d);
                //alert("ok men");
            },
            error: function() {
                alert("Error call service! Try again...");
            }
        });
    }

    function BuildTable(msg) {
        var table = '<table cellspacing="0" cellpadding="0" border="0" class="tblGray"><thead><tr><th>#</th><th>Tên văn bản</th><th>Lĩnh vực</th><th>Cơ quan</th></thead><tbody>';

        var i = 1;
        for (var post in msg) {
            var row = '<tr>';

            row += '<td style="width:25px">' + i++ + '</td>';
            row += '<td><a href="javascript:AddNewLegalControl(\'' + msg[post].Name + '\',' + msg[post].ID + ')"><b>' + msg[post].Name + '</b></a></td>';
            row += '<td>' + msg[post].Field + '</td>';
            row += '<td>' + msg[post].Office + '</td>';

            row += '</tr>';

            table += row;
        }

        table += '</tbody></table>';

        $('#DocContainer').html(table);
    }
</script>

<div id="leftpanecontentbox">
	<div class="topline"></div>
	<div id="leftcontent" class="left">
		<uc1:HNAP_AdminLeftNav ID="HNAP_AdminLeftNav1" runat="server" />
	</div>
	<div id="primarycontent2" class="left" style="margin-bottom:20px;">
		<div class="moduletitle">Cập nhật Danh mục TTHC</div>
		
		<table cellpadding="0" cellspacing="10" border="0">
		    <tr>
		        <td style="width:150px;">Tên TTHC:</td>
		        <td>
                    <asp:TextBox ID="txtName" runat="server" Width="600px"></asp:TextBox><br />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                        ErrorMessage="Bạn phải nhập tên TTHC." ControlToValidate="txtName" Display="Dynamic"></asp:RequiredFieldValidator>
                </td>
		    </tr>
		    <tr>
		        <td>Trình tự thực hiện:</td>
		        <td>
                    <SharePoint:InputFormTextBox runat="server" ID="txtSteps" 
                        RichText="true" RichTextMode="FullHTML" Rows="18" Style="height: 270px; width: 600px;"
                        TextMode="MultiLine" Width="600px"></SharePoint:InputFormTextBox>
                </td>
		    </tr>
		    <tr>
		        <td>Cách thực hiện thủ tục hành chính:</td>
		        <td>
                    <asp:TextBox ID="txtHowToPerform" runat="server" Width="600px"></asp:TextBox>
                </td>
		    </tr>
		    <tr>
		        <td>Thành phần hồ sơ:</td>
		        <td>
                    <SharePoint:InputFormTextBox runat="server" ID="txtCompositionOfRecord" 
                        RichText="true" RichTextMode="FullHTML" Rows="18" Style="height: 270px; width: 600px;"
                        TextMode="MultiLine" Width="600px"></SharePoint:InputFormTextBox>
                </td>
		    </tr>
		    <tr>
		        <td>Số bộ hồ sơ:</td>
		        <td>
                    <asp:TextBox ID="txtNumberOfRecord" runat="server" Width="600px"></asp:TextBox>
                </td>
		    </tr>
		    <tr>
		        <td>Thời hạn giải quyết:</td>
		        <td>
                    <asp:TextBox ID="txtTimeLimitPerform" runat="server" Width="600px"></asp:TextBox>
                </td>
		    </tr>
		    <tr>
		        <td>Đối tượng thực hiện thủ tục hành chính:</td>
		        <td>
                    <asp:TextBox ID="txtSubjectPerform" runat="server" Width="600px"></asp:TextBox>
                </td>
		    </tr>
		    <tr>
		        <td>Lĩnh vực của thủ tục hành chính:</td>
		        <td>
                    <asp:DropDownList ID="ddlField" runat="server" Width="250px">
                    </asp:DropDownList><br />
                    <asp:CompareValidator ID="CompareValidator1" runat="server" 
                        ErrorMessage="Bạn phải chọn ít nhất một lĩnh vực." Operator="NotEqual" ControlToValidate="ddlField" 
                        ValueToCompare="-1" Display="Dynamic"></asp:CompareValidator>
                </td>
		    </tr>
		    <tr>
		        <td>Cơ quan thực hiện thủ tục hành chính:</td>
		        <td>
                    <asp:DropDownList ID="ddlOffice" runat="server" Width="250px">
                    </asp:DropDownList><br />
                    <asp:CompareValidator ID="CompareValidator2" runat="server" 
                        ErrorMessage="Bạn phải chọn ít nhất một cơ quan." Operator="NotEqual" ControlToValidate="ddlOffice" 
                        ValueToCompare="-1" Display="Dynamic"></asp:CompareValidator>
                </td>
		    </tr>
		    <tr>
		        <td>Kết quả thực hiện thủ tục hành chính:</td>
		        <td>
                    <asp:TextBox ID="txtResultPerformAP" runat="server" Width="600px"></asp:TextBox>
                </td>
		    </tr>
		    <tr>
		        <td>Lệ phí:</td>
		        <td>
                    <asp:TextBox ID="txtFee" runat="server" Width="600px"></asp:TextBox>
                </td>
		    </tr>
		    <tr>
		        <td valign="top">Mẫu đơn, tờ khai:</td>
		        <td>
                    <asp:Repeater ID="rptAttachFile" runat="server" onitemcommand="rptAttachFile_ItemCommand">
                        <ItemTemplate>
                            <div>
                                <a href='<%#Eval("Link") %>' title='<%#Eval("Name") %>' target="_blank"><span style="font-weight:bold;"><%#Eval("Name") %></span></a>&nbsp;&nbsp;
                                [<asp:LinkButton ID="lbtDelFile" runat="server" CommandName="del" CommandArgument='<%#Eval("ID") %>' OnClientClick="javascript:return confirm('Bạn chắc chắn muốn xóa file này ?');" CssClass="redtext" CausesValidation="false"><span style="color:Red">xóa</span></asp:LinkButton>]
                            </div>
                        </ItemTemplate>
                    </asp:Repeater>
                    <table id="tblUpload" border="0" style="border-collapse: collapse;">
                        <script language="javascript">AddNewUploadControl(0)</script>											
                    </table>
                </td>
		    </tr>
		    <tr>
		        <td>Yêu cầu, điều kiện thực hiện thủ tục hành chính:</td>
		        <td>
                    <SharePoint:InputFormTextBox runat="server" ID="txtRequestAP" 
                        RichText="true" RichTextMode="FullHTML" Rows="18" Style="height: 270px; width: 600px;"
                        TextMode="MultiLine" Width="600px"></SharePoint:InputFormTextBox>
                </td>
		    </tr>
		    <tr>
		        <td valign="top">Căn cứ pháp lý của thủ tục hành chính:</td>
		        <td>
                    <div style="font-weight:bold;margin-bottom:5px">Danh sách văn bản:</div>
                    <asp:Repeater ID="rptLegal" runat="server" 
                        onitemcommand="rptLegal_ItemCommand">
                        <ItemTemplate>
                            <div>
                                <a href='<%= CurrentUrlWithoutParam %>?page=DocDetail&did=<%#Eval("ID") %>' title='<%#Eval("Name") %>' target="_blank"><span style="font-weight:bold;"><%#Eval("Name") %></span></a> 
                                [<asp:LinkButton ID="lbtDelFile" runat="server" CommandName="del" CommandArgument='<%#Eval("ID") %>' CssClass="redtext" CausesValidation="false"><span style="color:Red">xóa</span></asp:LinkButton>]
                            </div>
                        </ItemTemplate>
                    </asp:Repeater>
                    <asp:HiddenField ID="hdfDocsExist" runat="server" />
                    <div style="height:10px;border-bottom:1px #ccc solid;margin-bottom:10px">&nbsp;</div>
                    <table id="tblLegal" border="0" style="border-collapse: collapse;"></table>
                    <div style="margin-top:10px"><a href="#" id="create-user"><b>Thêm căn cứ pháp lý</b></a></div>
                </td>
		    </tr>
		    <tr>
		        <td>Trạng thái:</td>
		        <td>
                    <asp:CheckBox ID="cbEffectStatus" runat="server" Text="được công bố" /></td>
		    </tr>
		    <tr>
		        <td>Bình luận:</td>
		        <td>
                    <asp:CheckBox ID="cbCommentStatus" runat="server" Text="cho phép bình luận" /></td>
		    </tr>
		    <tr>
		        <td>&nbsp;</td>
		        <td>
                    <asp:LinkButton ID="lbtUpdate" runat="server" CssClass="btnstyle1" CausesValidation="true" 
                        onclick="lbtUpdate_Click">Cập nhật</asp:LinkButton>&nbsp;&nbsp;&nbsp;
                    <a href="<%=CurrentUrlWithoutParam + "?page=AdminAP" %>" title="" class="btnstyle2">Quay trở lại</a>
                </td>
		    </tr>
		</table>
        
	</div>
	
	<div class="clear"></div>
	
	<div id="dialog-form" title="Chọn căn cứ pháp lý">
	    <p style="border:1px #ccc solid;padding:3px">Bạn thực hiện tìm kiếm, sau đó chọn 1 văn bản làm căn cứ pháp lý bằng cách kích vào tiêu đề văn bản trong danh sách bên dưới.</p>
    	
	    Tên Văn bản:<asp:TextBox ID="txtDocName" runat="server" Width="200px"></asp:TextBox>&nbsp;
	    Lĩnh vực:<asp:DropDownList ID="ddlDocFields" runat="server" Width="150px"></asp:DropDownList>&nbsp;
	    Cơ quan:<asp:DropDownList ID="ddlDocOffices" runat="server" Width="150px"></asp:DropDownList>&nbsp;
	    <input type="button" value="Tìm kiếm" onclick="SearchDoc()" />
        
	    <div style="border-bottom:1px #ccc solid;height:1px;margin:10px 0 20px 0;"></div>
    	
	    <div id="DocContainer" ></div>
    </div>
</div>